import React from 'react'
import { Modal, message } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import { getRes } from "../../configFile";
import { deleteDevice } from '../../requests/Device';

//解构出confirm
const { confirm } = Modal;
export default function deleteDeviceModal(deviceID: number, deviceName: string, refresh: () => void) {
    confirm({
        title: `确认删除 ${deviceID} 吗`,
        icon: <ExclamationCircleOutlined />,
        content: '删除后可在回收站中恢复',
        onOk() {
            return deleteDevice(deviceID).then(msg => {
                const res = getRes(msg);
                if (res.isSuccessful) {
                    message.success('删除成功')
                    refresh()
                }
                else {
                    message.error('删除失败')
                }
            }).catch((err) => {
                console.log(err)
            })
        },
        onCancel() { },
    });
}